<template>
  <div>
    <a-row type="flex" :gutter="10">
      <a-col :span="12" style="height: calc(100vh - 125px)">
        <a-card :bordered="false" style="min-height: calc(100vh - 125px)">
          <!-- 条件搜索 -->
          <div class="table-page-search-wrapper">
            <a-form :labelCol="labelCol" :wrapperCol="wrapperCol" ref="queryForm">
              <a-row :gutter="32">
                <a-col :span="12">
                  <a-form-item label="地区状态">
                    <a-select placeholder="请选择地区状态" v-model="queryParam.status" style="width: 100%" allow-clear>
                      <a-select-option v-for="(d, index) in statusOptions" :key="index" :value="d.dictValue" @click="handleQuery">{{ d.dictLabel }}</a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :span="12" v-if="advanced">
                  <a-form-item label="地区名称">
                    <a-input v-model="queryParam.name" placeholder="请输入地区名称" allow-clear @keyup.enter.native="handleQuery" />
                  </a-form-item>
                </a-col>
                <a-col :span="12" v-if="advanced">
                  <a-form-item label="地区编码">
                    <a-input v-model="queryParam.code" placeholder="请输入地区编码" allow-clear @keyup.enter.native="handleQuery" />
                  </a-form-item>
                </a-col>
                <a-col :span="12" v-if="advanced">
                  <a-form-item label="地区类型">
                    <a-select placeholder="请选择地区类型" v-model="queryParam.type" style="width: 100%" allow-clear>
                      <a-select-option v-for="(d, index) in typeOptions" :key="index" :value="d.dictValue">{{ d.dictLabel }}</a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :span="12" v-if="advanced">
                  <a-form-item label="私有类型">
                    <a-select placeholder="请选择私有类型" v-model="queryParam.isPrivate" style="width: 100%" allow-clear>
                      <a-select-option v-for="(d, index) in isPrivateOptions" :key="index" :value="d.dictValue">{{ d.dictLabel }}</a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col>
                  <span class="table-page-search-submitButtons" style="float: right">
                    <a-button type="primary" @click="handleQuery"><a-icon type="search" />查询</a-button>
                    <a-button style="margin-left: 8px" @click="resetQuery"><a-icon type="redo" />重置</a-button>
                    <a @click="toggleAdvanced" style="margin-left: 8px">
                      {{ advanced ? '收起' : '展开' }}
                      <a-icon :type="advanced ? 'up' : 'down'" />
                    </a>
                  </span>
                </a-col>
              </a-row>
            </a-form>
          </div>
          <a-table
            :pagination="{
              current: queryParam.pageNum,
              pageSize: queryParam.pageSize,
              total: total,
              showSizeChanger: true,
              showLessItems: true,
              showQuickJumper: true,
              showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条，总计 ${total} 条`,
              onChange: changeSize,
              onShowSizeChange: onShowSizeChange
            }"
            tableKey="base-region-index-table"
            @change="handleTableChange"
            rowKey="id"
            size="middle"
            @refresh="getList"
            :columns="columns"
            :data-source="regionList"
            :loading="loading"
            :format-conditions="true"
            :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: 'radio' }"
            :scroll="{ x: 1500 }"
          >
            <span slot="avatar" slot-scope="text, record">
              <a-avatar shape="square" :src="imageUrl + record.avatar" />
            </span>
            <span slot="momentImage" slot-scope="text">
              <a-avatar shape="square" :src="text" />
            </span>
            <span slot="officialAccountImage" slot-scope="text">
              <a-avatar shape="square" :src="text" />
            </span>
            <span slot="receiveMoneyImage" slot-scope="text">
              <a-avatar shape="square" :src="text" />
            </span>
            <span slot="province" slot-scope="text, record">
              {{ getProvinceFormat(record) }}
            </span>
            <span slot="isPrivate" slot-scope="text, record">
              {{ isPrivateFormat(record) }}
            </span>
            <span slot="type" slot-scope="text, record">
              {{ typeFormat(record) }}
            </span>
            <span slot="status" slot-scope="text, record">
              <a-badge :status="statusBage(record.status)" :text="statusFormat(record)" />
            </span>
          </a-table>
        </a-card>
      </a-col>
      <a-col :span="12" style="height: calc(100vh - 125px); overflow-y: auto" id="box">
        <a-card :bordered="false" style="min-height: calc(100vh - 125px)">
          <region-detail :regionId="id" @getList="getList" :typeOptions="typeOptions" :isPrivateOptions="isPrivateOptions" :statusOptions="statusOptions" />
        </a-card>
      </a-col>
    </a-row>
    <a-back-top style="margin-right: -80px" :target="fn" />
  </div>
</template>

<script>
import allIcon from '@/core/icons'
import { listRegion, getInitData } from '@/api/platform/region'
import AdvanceTable from '@/components/pt/table/AdvanceTable'
import RegionDetail from './modules/RegionDetail'
import RegionApprove from './modules/RegionApprove'
import Area from '@/components/_util/Area'
export default {
  name: 'RegionApprove',
  components: {
    allIcon,
    AdvanceTable,
    RegionDetail
  },
  data() {
    return {
      //图片链接
      imageUrl: process.env.VUE_APP_BASE_API,
      open: false,
      // 遮罩层
      loading: true,
      // 选中
      id: undefined,
      // 高级搜索 展开/关闭
      advanced: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 选中的主键集合
      selectedRowKeys: [],
      // 总条数
      total: 0,
      // label的百分比
      labelCol: { span: 10 },
      // 内容区域的百分比
      wrapperCol: { span: 14 },
      // 地区表表格数据
      regionList: [],
      // 地区类型字典
      typeOptions: [],
      // 地区状态字典
      statusOptions: [],
      //  地区私有字典
      isPrivateOptions: [],
      // 查询参数
      queryParam: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        code: undefined,
        status: '1',
        type: undefined,
        isPrivate: undefined
      },
      expandedKeys: [],
      columns: [
        {
          title: '地区名称',
          dataIndex: 'name',
          ellipsis: true,
          align: 'left',
          width: '150px',
          fixed: 'left'
        },
        {
          title: '地区编码',
          dataIndex: 'code',
          ellipsis: true,
          align: 'center',
          width: '100px'
        },
        {
          title: '地区类型',
          dataIndex: 'type',
          ellipsis: true,
          align: 'center',
          width: '80px',
          scopedSlots: { customRender: 'type' }
        },
        {
          title: '地区头像',
          dataIndex: 'avatar',
          ellipsis: true,
          align: 'center',
          width: '20%',
          scopedSlots: { customRender: 'avatar' }
        },
        {
          title: '地区简称',
          dataIndex: 'abbreviation',
          ellipsis: true,
          align: 'left',
          width: '15%'
        },
        {
          title: '地区省份',
          dataIndex: 'province',
          ellipsis: true,
          align: 'left',
          width: '15%',
          scopedSlots: { customRender: 'province' }
        },
        {
          title: '朋友圈二维码',
          dataIndex: 'momentImage',
          ellipsis: true,
          align: 'center',
          width: '20%',
          scopedSlots: { customRender: 'momentImage' }
        },
        {
          title: '公众号二维码',
          dataIndex: 'officialAccountImage',
          ellipsis: true,
          align: 'center',
          width: '20%',
          scopedSlots: { customRender: 'officialAccountImage' }
        },
        {
          title: '收款码',
          dataIndex: 'receiveMoneyImage',
          ellipsis: true,
          align: 'center',
          width: '20%',
          scopedSlots: { customRender: 'receiveMoneyImage' }
        },
        {
          title: '私有状态',
          dataIndex: 'isPrivate',
          ellipsis: true,
          align: 'left',
          width: '10%',
          scopedSlots: { customRender: 'isPrivate' }
        },
        {
          title: '状态',
          dataIndex: 'status',
          ellipsis: true,
          align: 'left',
          width: '100px',
          scopedSlots: { customRender: 'status' },
          fixed: 'right'
        }
      ],
      pcaData: ''
    }
  },
  watch: {},
  created() {
    this.pcaData = new Area()
    this.getList()
    getInitData('region_type,region_status,region_private').then(response => {
      this.typeOptions = response.data.region_type
      this.statusOptions = response.data.region_status
      this.isPrivateOptions = response.data.region_private
    })
  },
  methods: {
    ...RegionApprove.methods,
    showSelectRegion() {
      this.open = true
      this.getList()
    },
    cancel(e) {
      this.open = false
    },
    /** 查询地区表列表 */
    getList() {
      this.loading = true
      this.selectedRowKeys = []
      this.id = undefined
      listRegion(this.queryParam).then(response => {
        this.regionList = response.data.rows
        if (response.data.rows.length > 0) {
          this.selectedRowKeys.push(this.regionList[0].id)
          this.id = this.regionList[0].id
        }
        this.total = response.data.total
        this.loading = false
      })
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.queryParam = {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        code: undefined,
        status: '1',
        type: undefined,
        isPrivate: undefined
      }
      this.handleQuery()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParam.pageNum = 1
      this.getList()
    },
    /** 翻页操作 */
    onShowSizeChange(current, pageSize) {
      this.queryParam.pageSize = pageSize
      this.getList()
    },
    /** 翻页操作 */
    onSizeChange(current, size) {
      this.queryParam.pageNum = 1
      this.queryParam.pageSize = size
      this.getList()
    },
    /** 翻页操作 */
    changeSize(current, pageSize) {
      this.queryParam.pageNum = current
      this.queryParam.pageSize = pageSize
      this.getList()
    },
    /** 翻页操作 */
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
      this.id = this.selectedRows[0].id
      this.single = selectedRowKeys.length !== 1
      this.multiple = !selectedRowKeys.length
    },
    /** 查询折叠和展开操作 */
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    handleTableChange(pagination, filters, sorter) {
      if (sorter.field !== undefined && sorter.field !== null && sorter.field !== '') {
        this.queryParam.orderByColumn = 'a.' + sorter.field
        this.queryParam.isAsc = sorter.order
      }
      this.getList()
    }
  }
}
</script>

<style></style>
